package com.cloud_sang.myrole;

import com.netflix.loadbalancer.AvailabilityFilteringRule;
import com.netflix.loadbalancer.BestAvailableRule;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassTitle: MySelfRule
 * @ProjectName springcould2020
 * @Description: Ribbon选取服务的规则配置 该配置类不可放在@ComponentScan所扫描的当前包下!!!!!!
 * @Author Sangsang
 * @Date 2020/12/29
 * @Time 23:36
 */
@Configuration
public class MySelfRule {

	@Bean
	public IRule myRule() {
		//return new RandomRule();//定义为随机
		//return new BestAvailableRule();//会先过滤掉由于多次访问故障而处于断路器跳闸状态的服务，然后选择一个并发量最小的服务
		return new AvailabilityFilteringRule();//先过滤掉故障实例，再选择并发较小的实例

	}
}

